<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>tab栏切换</title>
    <style>
        html,
        body,
        ul,
        li,
        div,
        img {
            margin: 0;
            padding: 0;
        }
        
        ul li {
            list-style: none;
        }
        
        .list1 {
            border: 1px solid #ccc;
            border-top: 0;
            margin: 100px auto;
            margin-bottom: 0px;
            background: #f6f6f6;
            /* border: 1px solid red; */
            line-height: 46px;
            text-align: center;
            width: 951px;
            height: 46px;
        }
        
        .list1 ul {
            clear: both;
        }
        
        .list1 ul li {
            color: #3c3c3c;
            float: left;
            width: 132px;
            height: 46px;
            border-right: 1px solid #ccc;
        }
        
        .list1 ul li.active {
            background: #fff;
            border-top: 0;
            border-bottom: 0;
            border-top: 2px solid #ff4400;
            color: #ff4400;
        }
        
        .list2 {
            margin: 0 auto;
            width: 951px;
            height: 340px;
            border: 1px solid #ccc;
            border-top: 0;
        }
        
        .list2 div {
            padding: 10px;
            display: none;
        }
        
        .style_orenge {
            color: #ff4400;
        }
    </style>
</head>

<body>
    <div class="list1">
        <ul>
            <li key="0">宝贝详情</li>
            <li key="1">积累评价 <span class="style_orenge">0</span></li>
            <li key="2">专享服务</li>
        </ul>
    </div>
    <div class="list2">
        <div id="items" style="display: block;">1111</div>
        <div id="items">2222</div>
        <div id="items">3333</div>
    </div>
    <script>
        let alis = $("li");

        let items = $("#items");

        for (let i = 0; i < alis.length; i++) {
            alis[i].onclick = function() {
                for (let j = 0; j < alis.length; j++) {
                    alis[j].className = "";
                }

                this.className = "active";
                this.setAttribute("index", i);
                let liIndex = this.getAttribute("index");
                // let key = this.getAttribute("key");
                console.log(liIndex);
                for (let k = 0; k < items.length; k++) {
                    items[k].style.display = "none";
                }

                items[liIndex].style.display = "block";
            }


        }

        function $(select) {
            return document.querySelectorAll(select);
        }
    </script>
</body>

</html>